/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package socof_trab1;

import dbaccess.Ficheiro;
import htmlparser.UrlParser;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ExecutorParser implements Runnable {

    private ResizeableSemaphore rs;
    private UrlParser parser = new UrlParser();
    ArrayList<String> links;
    //****************************************************************************************************************************
    //isto terá que vir da bd
    Integer id = 10;
    String dominio = "http://www.heu.com/";
    String ficheiro = "index.html";
    String estado = "parse";
    long tamanhosite = 100000;
    String caminhosite = "http://www.heu.com/";
    String caminholocal = "C:\\Users\\Helder\\Desktop\\";
    String tipo = "html";
    Integer niveis = 0;
    Date actualizado = new Date();
    Ficheiro dbObj = new Ficheiro(id, dominio, ficheiro, estado, tamanhosite, caminhosite, caminholocal, tipo, niveis, actualizado);
    //****************************************************************************************************************************

    public ExecutorParser(ResizeableSemaphore sem) throws InterruptedException {
        this.rs = sem;
        this.rs.acquire();
    }

    @Override
    public void run() {
        try {
            System.out.println("Parser: " + this.toString() + " started...");
//            aqui chamar o parser com os dados do ficheiro
            links = parser.getUrl(dbObj, "all");

            System.out.println(links.toString());

            Thread.sleep(2000);
            System.out.println("Parser: " + this.toString() + " finished...");

            this.rs.release();
        } catch (InterruptedException ex) {
            Logger.getLogger(ExecutorParser.class.getName()).log(Level.SEVERE, null, ex);

        }
    }
}
